﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ebclang.basics;
using myapp.messages.Stopuhr;
using myapp.specifications;

namespace myapp.portal
{
    public partial class FrmPortal : Form, IPortal
    {
        public FrmPortal()
        {
            InitializeComponent();
        }


        public void In_Zeitfortschritt(TimeSpan message)
        {
            if (this.InvokeRequired)
                this.Invoke(new Action<TimeSpan>(In_Zeitfortschritt), message);
            else
                this.label1.Text = new DateTime(message.Ticks).ToString("mm:ss");
        }


        public event Action<Start> Out_Start;
        public event Action<Stop> Out_Stop;
        public event Action<Request<GestoppteZeit, TimeSpan>> Out_GestoppteZeit;


        private void button1_Click(object sender, EventArgs e)
        {
            if (this.button1.Text == "Start")
            {
                this.Out_Start(new Start());
                this.button1.Text = "Stop";
                this.button2.Enabled = false;
            }
            else
            {
                this.Out_Stop(new Stop());
                this.button1.Text = "Start";
                this.button2.Enabled = true;
                this.label1.Text = "00:00";
            }
        }


        private void button2_Click(object sender, EventArgs e)
        {
            this.label1.Text = new DateTime(this.Out_GestoppteZeit
                                                .Request<GestoppteZeit, TimeSpan>(new GestoppteZeit())
                                                .Return().Ticks
                                           ).ToString("mm:ss");
        }
    }
}
